package Day2025_03_02;

import java.util.Arrays;

public class HomeWork01 {
    public static int[][] LuoXuan (int n) {
        if (n == 1) return new int[][]{{1}};
        if (n == 2) return new int[][]{{4, 3}, {1, 2}};
        // 遞歸尋找之前數組
        int[][] tmp = LuoXuan(n - 2);
        int[][] arr = new int[n][n];
        // 周圍
        for (int i = 0; i < n; i++) {
            arr[0][i] = n * n - i;
            arr[n - 1][i] = n * n - 3 * (n - 1) + i;
            arr[i][n - 1] = n * n - (n - 1) - i;
            if (i != 0) arr[i][0] = n * n - 4 * (n  - 1) + i;
        }
        // 內部
        for (int i = 1; i < n - 1; i++) {
            for (int j = 1; j < n - 1; j++)
                arr[i][j] = tmp[i - 1][j - 1];
        }
        return arr;
    }
    public static void main(String[] args) {
        int n = 10;
        int[][] arr = LuoXuan(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(arr[i][j] + "\t\t");
            }
            System.out.println();
        }
//        System.out.println(Arrays.deepToString(arr));
    }
}
